from django.db import models
from django.utils.translation import ugettext_lazy as _

from imagekit.models import ImageSpecField
from imagekit.processors import ResizeToFill
from model_utils.models import TimeStampedModel


class Cover(TimeStampedModel):
    """
    封面,论坛栏目的图标
    """
    # 封面
    cover = models.ImageField(_('cover'), upload_to='covers/%Y/%m/%d/')
    # 标题
    caption = models.CharField(_('caption'), max_length=255, blank=True)
    # 封面缩略图
    cover_thumbnail = ImageSpecField(source='cover',
                                     processors=[ResizeToFill(146, 146)],
                                     format='JPEG',
                                     options={'quality': 80})

    def __str__(self):
        return self.caption

    class Meta:
        verbose_name = _('cover')
        verbose_name_plural = _('cover')
